package com.fanh.service.impl;


import com.fanh.dao.GuideFavoriteDao;
import com.fanh.dto.GuideFavoriteResult;
import com.fanh.mapper.GuideFavoriteMapper;
import com.fanh.model.GuideFavorite;
import com.fanh.model.GuideFavoriteExample;
import com.fanh.service.GuideFavoriteService;

import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("guideGuideFavoriteService")
public class GuideFavoriteServiceImpl implements GuideFavoriteService {

    private static final Logger LOGGER = LoggerFactory.getLogger(GuideFavoriteServiceImpl.class);

    @Autowired
    private GuideFavoriteDao guideFavoriteDao;
    @Autowired
    private GuideFavoriteMapper guideFavoriteMapper;

    @Override
    public List<GuideFavoriteResult> coursefavList(String userId, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        return guideFavoriteDao.guideFavoriteList(userId);
    }

    @Override
    public boolean checkFav(String courseId, String userId) {

        GuideFavoriteExample example =new GuideFavoriteExample();
        example.createCriteria().andCourseIdEqualTo(courseId).andUserIdEqualTo(userId);
       List list = guideFavoriteMapper.selectByExample(example);

        if(list != null && list.size()>0) {
            return true;
        } else {
            return false;
        }
     }

    @Override
    public int deleteCoursefav(String courseId, String userId) {
        GuideFavoriteExample example =new GuideFavoriteExample();
        example.createCriteria().andCourseIdEqualTo(courseId).andUserIdEqualTo(userId);
        return guideFavoriteMapper.deleteByExample(example);
    }

    @Override
    public int insert(GuideFavorite guideFavorite) {
        guideFavorite.setFavoriteTime(new Date());
        return  guideFavoriteMapper.insertSelective(guideFavorite);

    }
}
